package com.mybatis.jpa.sqlbuilder.query.condition;

import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

public class In implements Condition {
    @Override
    public String getPart(ConditionParam param) {
        List list = (List) param.getParamMap().get(param.getParamKey());
        String str = "#{%s[%d]}";
        List<String> values = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            values.add(String.format(str, param.getParamKey(), i));
        }
        return " and " + param.getColumnName() + " in (" + StringUtils.join(values, ",") + ")";
    }
}
